import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import Clist from '../views/Clist.vue'

Vue.use(VueRouter)

const routes = [{
  path: '/login',
  name: 'login',
  component: Login
}, {
  path: '/home',
  name: 'home',
  component: Home,
  children: [{
    path: '/clist',
    name: 'clist',
    component: Clist,
  }]
}]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  let rs = JSON.parse(localStorage.getItem("rs"));
  if (to.name != 'login' && rs.apiKey != '999')
   return next({name: 'login'})
  next();
})

export default router
